<!DOCTYPE html>
<html lang="en">
<head>
    <title>新增需求</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-store, must-revalidate">
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT">
    <meta http-equiv="expires" content="-1">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="refresh" content="1200">
    <link rel="shortcut icon" href="/dist/img/icon.png" type="image/x-icon">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="/dist/plugins/bootstrap/css/bootstrap.min.css">
    <!--字体-->
    <link rel="stylesheet" href="/dist/css/font-awesome.min.css">
    <!--图标-->
    <link rel="stylesheet" href="/dist/css/ionicons.min.css">
    <!--OA主样式-->
    <link rel="stylesheet" href="/dist/css/OA.min.css?t=86e2297f">
    <link rel="stylesheet" href="/dist/css/skins/OA-skins.min.css?t=222aea35">
    <link rel="stylesheet" href="//at.alicdn.com/t/font_855021_df13d5353cs.css">
    <link rel="stylesheet" href="/dist/plugins/webuploader-0.1.5/webuploader.css">
    
    <style>
        textarea{
            padding: 0;
        }
        .webuploader-pick {
            background: url(/dist/img/fjT1.png) no-repeat 5px center;
            display: block;
            padding: 0 4px;
            height: 22px;
            line-height: 22px;
            padding-left: 15px;
            margin: 0 auto;
            width: 70px;
            border-radius: 4px;
            color: #2a8cec;
        }
        .webuploader-pick-hover {
            color: #fff !important;
            background: url(/dist/img/fjT2.png) no-repeat 5px center;
            background-color: #0F6099;

        }
        .lineOne {
            text-align: left;
        }

        .lineOne span {
            max-height: 20px;
            line-height: 20px;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 1;
            text-align: left;
        }

        .div-td-content-more {
            position: absolute;
            height: auto;
            z-index: 999;
            line-height: 20px;
            background-color: #d3e8fd;
            padding: 8px 6px;
            border: 1px solid #e8e8ea;
            display: none;
        }

        .div-td-content-more i {
            width: 15px;
            height: 12px;
            background: url("/dist/img/more-icon.png");
            position: absolute;
            left: 50px;
            top: -12px;
        }

        .tdColor {
            width:190px;
            background-color: #f8f8f8;
        }

        .tdColor .icon-ren,.tdColor .icon-ren3{
            position: absolute;
            font-size: 16px;
        }
        .tdColor .icon-bixutian{
            font-size: 12px;
            color: red;
        }

        .td-value {
            text-align: left !important;
            vertical-align: middle;
            word-wrap: break-word;
            color: #2a8cec !important;
        }

        .td-value span {
            display: inline-block;
            max-height: 56px;
            overflow: hidden;
            padding: 0 6px;
            word-wrap: break-word;
            text-align: center !important;
        }
        .td-value1 {
            text-align: left !important;
            vertical-align: middle;
            word-wrap: break-word;
            color: #2a8cec !important;
            position: relative;
        }
        .td-value1 .user{
            display: inline-block;
            float: left;
            overflow: hidden;
            cursor: pointer;
        }
        .user.select{
            color: #fff;
            background-color: #045B9E;
        }
        .td-value1 input,textarea{
            width: 100%;
            border: 0;
            outline: none;
        }
        .weChat{
            position: absolute;
            left: 200px;
            margin-top: 2px;
        }
        .weChat input{
            position: absolute;
            bottom: 18px;
            left: -15px;
        }

        .head td{
            background-color: yellow;
        }

        .t-center input,.t-center{
            text-align: center !important;
        }
        
        .operating{
            text-align: right;line-height:30px;color: #2a8cec 
        }
        .operating span{
            margin-left: 10px;
            cursor: pointer;
        }
        .table>thead>tr>th{
            background:#d3e8fd !important;
        }
        .overdue{
            color: red !important;
        }
        
    </style>
</head>
<body>
<iframe id="ifAttach" style="display:none"></iframe>
<section class="content" id="app"  style="width: 650px;margin: 0 auto">
    <!-- <div class="tableTitle" v-if="jiaose=='kf'" style="text-align: center;font-weight: bold;font-size: 20px">开发分解</div>
    <div class="tableTitle" v-else-if="pageType=='decomposition'" style="text-align: center;font-weight: bold;font-size: 20px">需求分解</div>
    <div class="tableTitle" v-else style="text-align: center;font-weight: bold;font-size: 20px">新增需求</div> -->

    <table class="table table-bordered text-center table-width">
        <tbody>
            <tr>
                <td class="tdColor" v-if="mainInfo.proLevel==1">需求名称</td>
                <td class="tdColor" v-if="mainInfo.proLevel==2">需求分解描述</td>
                <td class="td-value1" >
                    <textarea  v-if="isFZR" style="resize: none" v-model="mainInfo.proName"></textarea>
                    <span  v-if="!isFZR" >{{mainInfo.proName}}</span>
                </td>
            </tr>
            <!-- <tr>
                <td class="tdColor">需求类型</td>
                <td class="td-value1" >
                    <input type="isFZR" v-model="mainInfo.proType"/>
                    <span  v-if="!isFZR" >{{mainInfo.proType}}</span>
                </td>
            </tr> -->
            <tr v-if="mainInfo.proLevel==1">
                <td class="tdColor">需求描述</td>
                <td class="td-value1">
                    <textarea rows="4" v-if="isFZR"  style="resize: none" v-model="mainInfo.proDesc"></textarea>
                    <textarea rows="4" v-if="!isFZR" readonly style="resize: none" v-model="mainInfo.proDesc"></textarea>
                </td>
            </tr>
            <tr v-if="authorityList.cpLeader">
                <td class="tdColor">需求提出人</td>
                <td class="td-value1" >
                    <input class="pull-left demandPerson" style="width:100px" v-model="mainInfo.proPrincipalName" placeholder="请输入需求提出人"
                    type="text" @keyup.delete="delDemandPerson"/>
                </td>
            </tr>
            <tr v-if="authorityList.cpLeader">
                <td class="tdColor">{{rightName}}负责人</td>
                <td class="td-value1" >
                    <div>
                        <div v-for="(user,i) in mainInfo.proPrincipals" class="user"
                            v-bind:class="{ select: principalsSelectIndex == i }"
                            v-on:click="selectUser('principalsSelectIndex',i)">{{user.userName}}{{(mainInfo.proPrincipals.length-i==1)?'':','}}
                        </div>
                        <input class="pull-left kfLeader" style="width:100px" :placeholder="mainInfo.proPrincipals.length==0?'可以输入多人':''"
                            type="text" @keyup.delete="delMainPerson"  @blur="blurInput('principalsSelectIndex')"/>
                    </div>
                </td>
            </tr>
            <tr v-if="authorityList.cpLeader||authorityList.kfLeader">
                <td class="tdColor">抄送人</td>
                <td class="td-value1" >
                    <div>
                        <div v-for="(user,i) in mainInfo.csPerson" class="user"
                            v-bind:class="{ select: csPersonSelectIndex == i }"
                            v-on:click="selectUser('csPersonSelectIndex',i)">{{user.userName}}{{(mainInfo.csPerson.length-i==1)?'':','}}
                        </div>
                        <input class="pull-left mainCsPerson" style="width:100px" :placeholder="mainInfo.csPerson==0?'可以输入多人':''"
                            type="text" @keyup.delete="delCsPerson"  @blur="blurInput('csPersonSelectIndex')"/>
                    </div>
                </td>
            </tr>
            <tr v-if="pageType=='decomposition' && authorityList.cpLeader">
                <td class="tdColor">状态</td>
                <td class="td-value1" >
                    <select v-model="mainStatus" style="width:100%;text-align-last:center;border:0" >
                        <option value="1">未完成</option>
                        <option value="2">已完成</option>
                    </select>
                </td>
            </tr>
        </tbody>
    </table>

    <div v-if="pageType=='decomposition' && isFZR" class="operating">
        <span @click="addRow()">添加一行</span>
        <span @click="delRow()">删除一行</span>
    </div>
    <table v-if="pageType=='decomposition'" class="table table-bordered text-center table-width">
        <thead>
            <tr class="head">
                <th style="width:30px;">序号</th>
                <th style="width:300px;" v-if="jiaose=='cp'">{{leftName}}分解</th>
                <th style="width:300px;" v-if="jiaose=='kf'">{{rightName}}分解</th>
                <th>负责人</th>
                <th style="width:80px;">开始时间</th>
                <th style="width:80px;">结束时间</th>
                <th v-if="childList.length>0">状态</th>
            </tr>
            </thead>
            <tbody>
            <tr v-if="childList.length==0">
                <td colspan="5" style="font-size:20;font-weight: bold;height: 50px;">暂无分解任务</td>
            </tr>
            <tr v-for="(item,i) in childList">
                <td>{{i+1}}</td>
                <td class="td-value1">
                    <input type="text" v-if="isFZR" v-model="item.proName" @focus="rowSelected(i)"/>
                    <input type="text" v-if="!isFZR" readonly v-model="item.proName" @focus="rowSelected(i)"/>
                </td>
                <td class="td-value1 t-center">
                    <input class="pull-left proPrincipal" v-if="isFZR" v-model="item.proPrincipalName" style="width:100%" type="text" @keyup.delete="delProPrincipal(item)" @focus="rowSelected(i)"/>
                    <input class="pull-left proPrincipal" v-if="!isFZR" readonly v-model="item.proPrincipalName" style="width:100%" type="text" @keyup.delete="delProPrincipal(item)" @focus="rowSelected(i)"/>
                </td>
                <td class="td-value1 t-center">
                    <input type="text" v-if="isFZR" @focus="showDatePicker($event,item,'startTime')" v-model="item.startTime"/>
                    <input type="text" v-if="!isFZR" readonly v-model="item.startTime"/>
                </td>
                <td class="td-value1 t-center">
                    <input type="text" v-if="isFZR" @focus="showDatePicker($event,item,'endTime')"  v-model="item.endTime"/>
                    <input type="text" v-if="!isFZR" readonly  v-model="item.endTime"/>
                </td>
                <td class="td-value1 t-center" :class="item.status==6?'overdue':''">
                    <span v-if="item.status==''"></span>
                    <span v-if="item.status==1">未开始</span>
                    <span v-if="item.status==2">进行中</span>
                    <span v-if="item.status==3">完成</span>
                    <span v-if="item.status==4">已完成-待审核</span>
                    <span v-if="item.status==5">已撤销</span>
                    <span v-if="item.status==6">已逾期</span>
                </td>
            </tr>
        </tbody>
    </table>
    
    <div class="south" v-if="isFZR" style="height:50px;line-height:50px;text-align:center;">
        <input type="button" value="保存" class="btn oaBtn btn-sm" @click="saveInfo()"/>
        <input type="button" v-if="pageType!='add' && jiaose=='cp'" value="撤销" class="btn oaBtn btn-sm" @click="updateProStatus(5)"/>
    </div>
</section>
<!--JQ-->
<script src="https://file.ggxqce.com/web/jquery-2.2.3.min.js"></script>
<!--插件JS-->
<script src="https://file.ggxqce.com/web/bootstrap.min.js"></script>
<!--框架已定义 JS-->
<script src="/dist/js/app_iframe.js?t=8e743a31"></script>
<!--oa自定义  JS-->
<script src="/dist/js/oa.js?t=54c6b89c"></script>
<script src="https://file.ggxqce.com/web/vue.min.js"></script>
<script type="text/javascript" src="/dist/plugins/lhgdialog/lhgdialog.min.js?self=true"></script>
<script type="text/javascript" src="/dist/plugins/My97DatePicker/WdatePicker.js"></script>
<script src="/dist/plugins/webuploader-0.1.5/webuploader.min.js"></script>
<script type="text/javascript" src="/dist/js/pages/common/commonService.js"></script>
<script type="text/javascript">
    var api = frameElement.api, W = api.opener;
    var app = new Vue({
        el: '#app',
        data: {
            mainStatus:1,
            pageType:"add",
            taskSelectedIndex:"-1",
            isFZR:true,
            jiaose:"cp",
            rightName:'',
            userId:getCurrentUser().id,
            principalsSelectIndex:-1,
            csPersonSelectIndex:-1,
            mainInfo:{"proLevel":1,"status":"","proPrincipals":[],"proPrincipal":"","proPrincipalName":"","csPerson":[]},
            childList:[],
            delIds:"",
            authorityList:{cpLeader:false,kfLeader:false}
        },
        methods: {
            getInfoById:function(){
                var that = this;
                $.wyui.postMethod(urlConfig.system.rightOp.getRightOpByUserId, {userId: that.userId}, function (data) {
                    for (var i = 0; i < data.length; i++) {
                        that.authorityList[data[i].eName] = true;
                    }
                },true);

                setTimeout(() => {
                    initAutoComplete();
                }, 300);

                if(this.pageType=="add")
                    return false;

                $.wyui.postMethod(urlConfig.pm.projectTrack.getProInfoByParentId, {
                    "projectId":that.mainInfo.id,
                    "jiaose":that.jiaose,
                    "userId":getCurrentUser().id
                }, function (data) {
                    that.childList = data.childList;
                    that.mainInfo = data.info;
                    if(data.info.iskfleader == "1"){
                        that.authorityList.kfLeader = true;
                        Vue.set(that.authorityList,"kfLeader",true);
                    }
                    if(that.mainInfo.proPrincipals==undefined)
                        that.mainInfo.proPrincipals =new Array();
                    if(that.mainInfo.csPerson == undefined)
                        that.mainInfo.csPerson = new Array();
                   
                    if(data.info.status!=3)
                        that.mainStatus = 1;
                    else
                        that.mainStatus = 2;

                    if((that.authorityList.cpLeader || that.authorityList.kfLeader) && data.childList.length==0){
                        for(var i=0;i<3;i++){
                            var obj=new Object();
                            obj.id="";
                            obj.proPrincipal="";
                            obj.proPrincipalName="";
                            obj.startTime="";
                            obj.endTime="";
                            obj.proName="";

                            that.childList.push(obj);
                        }
                    }

                    if((that.authorityList.cpLeader && that.jiaose=='cp') ||(that.authorityList.kfLeader&& that.jiaose=='kf'))
                        that.isFZR=true;
                    else
                        that.isFZR=false;
                    setTimeout(() => {
                        initAutoComplete();
                    }, 300);
                });
            },
            saveInfo:function(){
                var that = this;
                if(that.mainInfo.proName==undefined || that.mainInfo.proName==""){
                    alert("请输入需求名称")
                    return false;
                }
                if(that.mainInfo.proDesc==undefined || that.mainInfo.proDesc==""){
                    alert("请输入需求描述")
                    return false;
                }
                if(that.mainInfo.proPrincipal==undefined || that.mainInfo.proPrincipal==""){
                    alert("请输入需求提出人")
                    return false;
                }

                var flag =false

                for(var i=0;i<that.childList.length;i++){
                    var row =i+1;
                    if(that.childList[i].proName==""){
                        alert("请输入第"+row+"行需求分解名称")
                        flag =true;
                    }
                    // else if(that.childList[i].proPrincipal==""){
                    //     alert("请输入第"+row+"行负责人")
                    //     flag =true;
                    // }else if(that.childList[i].startTime==""){
                    //     alert("请输入第"+row+"行开始时间")
                    //     flag =true;
                    // }else if(that.childList[i].endTime==""){
                    //     alert("请输入第"+row+"行结束时间")
                    //     flag =true;
                    // }
                    if(flag)
                        return false;
                }

                if(that.mainStatus==2)
                    that.mainInfo.status = 3;

                $.wyui.postMethod(urlConfig.pm.projectTrack.saveInfo, {
                    "mainInfo":that.mainInfo,
                    "childList":that.childList,
                    "userId": getCurrentUser().id,
                    "userName": getCurrentUser().name,
                    "delIds":that.delIds,
                    "jiaose":that.jiaose
                }, function (data) {
                    if(that.pageType="add"){
                        location.href = "addPro.html?pageType=decomposition&projectId="+data.result+"&jiaose=cp";
                    }
                    parent.refresh();
                    api.close();
                    // that.getInfoById();
                });
            },
            updateProStatus:function(type){
                var that = this;
                if(confirm("确定撤销该需求？")){
                    $.wyui.postMethod(urlConfig.pm.projectTrack.updateProStatus, {
                        projectId:that.mainInfo.id,
                        status:type,
                    }, function (data) {
                        parent.refresh();
                        api.close();
                        // that.getInfoById();
                    });
                }
            },
            showDatePicker: function (e, item,type) {
                WdatePicker({
                    onpicked: function (dp) {
                        if(type == 'startTime')
                            item.startTime = dp.cal.getNewDateStr();
                        else
                            item.endTime = dp.cal.getNewDateStr();
                        return true;
                    }
                });
                $(e.target).blur();
            },
            delDemandPerson:function(){
                this.mainInfo.proPrincipal = "";
            },
            delMainPerson:function(){
                if (event.keyCode == 46 || event.keyCode == 8 && event.target.value == "") {
                    if (this.principalsSelectIndex > -1) {
                        this.mainInfo.proPrincipals.splice(this.principalsSelectIndex, 1);
                        this.principalsSelectIndex = -1;
                    } else {
                        this.principalsSelectIndex = this.mainInfo.proPrincipals.length - 1;
                    }
                }
            },
            delCsPerson:function(){
                if (event.keyCode == 46 || event.keyCode == 8 && event.target.value == "") {
                    if (this.csPersonSelectIndex > -1) {
                        this.mainInfo.csPerson.splice(this.csPersonSelectIndex, 1);
                        this.csPersonSelectIndex = -1;
                    } else {
                        this.csPersonSelectIndex = this.mainInfo.csPerson.length - 1;
                    }
                }
            },
            blurInput(prop){
                this[prop] = -1;
            },
            selectUser: function (prop,i) {
                this[prop]
                if(this[prop] == i)
                this[prop] = -1;
                else
                this[prop] = i;
            },
            rowSelected:function(index){
                this.taskSelectedIndex = index;
            },
            delProPrincipal:function(item){
                item.proPrincipal="";
            },
            addRow:function(){
                var o=new Object();
                o.id="";
                o.startTime="";
                o.endTime="";
                o.proPrincipal="";
                o.proPrincipalName="";

                if(this.taskSelectedIndex==-1)
                    this.taskSelectedIndex = this.childList.length-1;

                this.childList.splice(this.taskSelectedIndex+1,0,o);

                setTimeout(() => {
                    initAutoComplete();
                }, 200);
            },
            delRow:function(){
                if(this.taskSelectedIndex==-1)
                    this.taskSelectedIndex = this.childList.length-1;
                    
                this.delIds = this.delIds + this.childList[this.taskSelectedIndex].id+',';

                this.childList.splice(this.taskSelectedIndex,1);
                if(this.childList.length<=this.taskSelectedIndex)
                    this.taskSelectedIndex = this.childList.length-1;
            }
        },
        mounted: function () {
            this.pageType = $.wyui.page.urlParams.pageType;
            this.mainInfo.id = $.wyui.page.urlParams.projectId;
            this.jiaose = $.wyui.page.urlParams.jiaose;
            this.rightName = $.wyui.page.urlParams.rightName;
            this.leftName = $.wyui.page.urlParams.leftName;
            // Vue.set();
            // Vue.set(this.mainInfo, "id",$.wyui.page.urlParams.projectId)
            // Vue.set(this.jiaose, $.wyui.page.urlParams.jiaose)

            this.getInfoById();
        }
    });
</script>
<script>
    $(function(){
        initAutoComplete = function(){
            $(".proPrincipal,.kfLeader,.mainCsPerson,.demandPerson").autoComplete({
                url: server.ip + urlConfig.system.user.getTop10ByNameUser,
                render: function (users, panel) {
                    for (var i = 0; i < users.length; i++) {
                        $("<li></li>").data("autoComplete",
                            users[i]).html("<a>" + users[i].name + "&nbsp;&nbsp;&nbsp;" +
                            "(" + "&nbsp;" + users[i].companyName + "-" + users[i].departName + "-" + users[i].roleName + "&nbsp;" + ") " + "</a>")
                            .appendTo(panel);
                    }
                },
                selected: function (user) {
                    if ($(this).hasClass("proPrincipal")) {
                        var selectIndex = app.taskSelectedIndex;
                        app.childList[selectIndex].proPrincipal = user.id;
                        app.childList[selectIndex].proPrincipalName = user.name;
                       
                    }else if($(this).hasClass("kfLeader")){
                        var userIds = new Array();
                        for (var i = 0; i < app.mainInfo.proPrincipals.length; i++) {
                            userIds.push(app.mainInfo.proPrincipals[i].id);
                        }
                        if ($.inArray(user.id, userIds) == -1) {
                            app.mainInfo.proPrincipals.push({id: user.id, userName: user.name, isNew: true});
                            
                        } else {
                            alert(app.rightName+"负责人不能重复输入");
                        }
                        Vue.set(app.mainInfo); 
                        app.principalsSelectIndex = app.mainInfo.proPrincipals.length - 1;
                        app.principalsSelectIndex = -1;
                        
                        $(this).val("");
                    }else if($(this).hasClass("mainCsPerson")){
                        var userIds = new Array();
                        for (var i = 0; i < app.mainInfo.csPerson.length; i++) {
                            userIds.push(app.mainInfo.csPerson[i].id);
                        }
                        if ($.inArray(user.id, userIds) == -1) {
                            app.mainInfo.csPerson.push({id: user.id, userName: user.name, isNew: true});
                            
                        } else {
                            alert("抄送负责人不能重复输入");
                        }
                        Vue.set(app.mainInfo); 
                        app.csPersonSelectIndex = app.mainInfo.csPerson.length - 1;
                        app.csPersonSelectIndex = -1;
                        
                        $(this).val("");
                    }else if($(this).hasClass("demandPerson")){
                        app.mainInfo.proPrincipal = user.id;
                        app.mainInfo.proPrincipalName = user.name;
                    }
                    return false;
                },
                height: 180,
                width: 300
            });
        }

    });
</script>

</body>
</html>